
function timeOut(ms){

  return new Promise((resolve,reject)=>{
    setTimeout(resolve, ms,'done');
  })
}

// timeOut(2000).then((value)=>{
//   console.log(value)
// })

function testPromise(ready) {
  return new Promise(function(resolve,reject){
    if(ready) {
      resolve("hello world");
    }else {
      reject("No thanks");
    }
  });
};
// 方法调用
// testPromise(false).then(function(msg){
//   console.log(msg);
// },function(error){
//   console.log(error);
// });


// async function testFetch(){
//   const res = await fetch('https://p9s5xa.laf.run/handleFetch')

//   console.log(res)
// }

// testFetch()


// let fs = require('fs')
// function read(url){
//   return new Promise((resolve,reject)=>{
//     fs.readFile(url,'utf8',function(error,data){
//       error && reject(error)
//       resolve(data)
//     })
//   })
// }

// read('./a.txt').then(data=>{
//   return read(data) 
// }).then(data=>{
//   return read(data)  
// }).then(data=>{
//   console.log(data)
// })


console.log('script start')
let promise1 = new Promise(function (resolve) {
    console.log('promise1')
    resolve()
    console.log('promise1 end')
}).then(function () {
    //console.log('promise2')
    setTimeout(()=>{
      console.log('then')
    },0)
})
setTimeout(function(){
    console.log('settimeout')
})
console.log('script end')
// 输出顺序: script start->promise1->promise1 end->script end->promise2->settimeout
